package com.example.java.base.concurrency.threadpool;

import com.example.java.base.concurrency.threadpool.task.ExecutorTask;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * A3_SingleThreadExecutor:工具类创建线程池方式1:Executors.newSingleThreadExecutor()
 *
 * @author zhangxiaoxiang
 * @date 2020/11/5
 */
public class A3SingleThreadExecutor {
    public static void main(String[] args) {
        //允许的请求队列长度为Integer.MAX_VALUE，可能会堆积大量的请求，从而导致OOM
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 1000; i++) {
            //线程数为1个,但是请求多余1个的线程直接放在队列,是无界队内,处于堆积状态
            executorService.execute(new ExecutorTask());

        }
    }
}
